package com.mp.approvalreq.servlet;

import com.alibaba.fastjson.JSONObject;
import com.mp.approvalreq.service.ApprovalOperateServicePrx;
import com.mp.approvalreq.util.ServiceUtils;
import com.mp.user.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *  左滑全部已读
 */
@WebServlet("/removeCcRedpoint")
public class RemoveCcRedpoint extends AbstractServlet {
	
	private static final Logger logger = LoggerFactory.getLogger(RemoveCcRedpoint.class);

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			User user = getReqUser(req);
			
			Integer type = Integer.valueOf(req.getParameter("type"));
			
			ApprovalOperateServicePrx approvalOperateServicePrx = ServiceUtils.getApprovalOperateServicePrx();
			approvalOperateServicePrx.removeCcRedpoint(user, type);
			
			printResult(resp);
		} catch (Throwable e) {
			onThrowable(req, resp, e);
		}
	}
	
	private void printResult(HttpServletResponse resp) throws IOException {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("result", "0");
		jsonObject.put("res_info", "成功");
		
		logger.info(jsonObject.toJSONString());
		
		printJson(resp, jsonObject.toJSONString());
	}
}
